package pack1;

public class RunablePK implements Runnable {
    private Person p1;
    private Person p2;

    public RunablePK(Person p1, Person p2) {
        this.p1 = p1;
        this.p2 = p2;
    }

    private boolean sw = true;

    public void run() {
        while (sw) {
            if(Math.random()>=0.5){
                System.out.println(p1.getName()+" 重重地打了 " + p2.getName());
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }else{
                System.out.println(p2.getName()+" 轻轻地摸了 " + p1.getName());
                try {
                    Thread.sleep(2000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }
    }

    public void close() {
        this.sw = false;
    }
}
